﻿#region 命名空间

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Xml;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Admin.Member
{
    public partial class Setting : WebFactory.PageBase
    {
        private readonly RoleManage _myBll = new RoleManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            this.L_Path.Text = "会员管理 → 会员设置 ";
            if (!IsPostBack)
            {
                ServerControl.BindDropDownList(this.ddlMemberRole, this._myBll.BindList(false), "RoleName", "ID", null);

                if (this.ddlMemberRole.Items.Count < 1)
                {
                    MsgBox.Message("请先设置会员角色", this.UpdatePanel1);
                }
                try
                {
                    ReadMemberConfigXml();
                }
                catch (Exception Ex)
                {
                    MsgBox.Message(Ex.Message, this.UpdatePanel1);
                }
            }
        }

        #region Member

        private void ReadMemberConfigXml()
        {
            var config = CMSConfig.Instance();
            this.cbkIsReg.Checked = config.Member.IsReg;
            this.cbkIsAdminCheck.Checked = config.Member.IsAdminCheck;
            this.cbkIsPassCode.Checked = config.Member.IsPassCode;
            this.NtxtJianYanHuiLv.Text = config.Member.JianYanHuiLv.ToString();
            this.NtxtJingBiHuiLv.Text = config.Member.JingBiHuiLv.ToString();
            this.txtJingBiMingCheng.Text = config.Member.JingBiMingCheng;
            this.NtxtPoint.Text = config.Member.Point.ToString();
            this.NtxtCoin.Text = config.Member.Coin.ToString();
            this.ddlMemberRole.SelectedValue = config.Member.MemberRoleID.ToString();
            this.txtPayment.Text = config.Member.Payment;
        }

        private void WriteMemberConfigXml()
        {
            var config = CMSConfig.Instance();
            config.Member.IsReg = this.cbkIsReg.Checked;
            config.Member.IsAdminCheck = this.cbkIsAdminCheck.Checked;
            config.Member.IsPassCode = this.cbkIsPassCode.Checked;
            config.Member.JianYanHuiLv = Convert.ToDouble(this.NtxtJianYanHuiLv.Text);
            config.Member.JingBiHuiLv = Convert.ToDouble(this.NtxtJingBiHuiLv.Text);
            config.Member.JingBiMingCheng = this.txtJingBiMingCheng.Text;
            config.Member.Point = int.Parse(this.NtxtPoint.Text);
            config.Member.Coin = int.Parse(this.NtxtCoin.Text);
            config.Member.MemberRoleID = int.Parse(this.ddlMemberRole.SelectedValue);
            config.Member.Payment = this.txtPayment.Text;
            config.Save(config);
        }

        #endregion

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                WriteMemberConfigXml();
                MsgBox.Message("操作完成！", this.UpdatePanel1);
            }
            catch
            {
                MsgBox.Message("保存错误！", this.UpdatePanel1);
            }
        }
    }
}